inventorycontextmenu={}
cratecontextmenu=function(SpawnIcon,key,id)
			local MenuButtonOptions=DermaMenu()
			local invnt=SpawnIcon:GetParent():GetParent():GetParent()
			buildmultimenu(MenuButtonOptions,key.." "..id,"Take",invnt)
			MenuButtonOptions:Open()
			end

inventorycontextmenu["default"]=function(SpawnIcon,key)
				local MenuButtonOptions = DermaMenu() // Creates the menu
				local invnt=SpawnIcon:GetParent():GetParent():GetParent()
				buildcrate(MenuButtonOptions,key, invnt)
				buildmultimenu(MenuButtonOptions,key,"Drop", invnt)
				MenuButtonOptions:Open()
			end


inventorycontextmenu["melon"]=function(SpawnIcon, key)
				local MenuButtonOptions = DermaMenu() // Creates the menu
				local invnt=SpawnIcon:GetParent():GetParent():GetParent()
				buildmultimenu(MenuButtonOptions,key,"Eat",invnt)
				buildmultimenu(MenuButtonOptions,key,"Drop",invnt)
				buildcrate(MenuButtonOptions,key, invnt)											
				MenuButtonOptions:Open() // Open the menuy AFTER adding your options 
			end

inventorycontextmenu["glock_world"]=function(SpawnIcon,key)
				local MenuButtonOptions = DermaMenu() // Creates the menu		
				local invnt=SpawnIcon:GetParent():GetParent():GetParent()
				singlemenu(MenuButtonOptions,key,"Equip",invnt)
				buildmultimenu(MenuButtonOptions,key,"Drop",invnt)
				buildcrate(MenuButtonOptions,key, invnt)											
				MenuButtonOptions:Open() // Open the menuy AFTER adding your options 
			end

inventorycontextmenu["super_shotgun_world"]=function(SpawnIcon,key) inventorycontextmenu["glock_world"](SpawnIcon,key) end

inventorycontextmenu["mac10_world"]=function(SpawnIcon,key) inventorycontextmenu["glock_world"](SpawnIcon,key) end

inventorycontextmenu["axe_world"]=function(SpawnIcon,key) inventorycontextmenu["glock_world"](SpawnIcon,key) end

inventorycontextmenu["wood"]=function(SpawnIcon,key)
				local MenuButtonOptions = DermaMenu() // Creates the menu		
				local invnt=SpawnIcon:GetParent():GetParent():GetParent()
				singlemenu(MenuButtonOptions,key,"BuildCrate",invnt)

				buildcrate(MenuButtonOptions,key, invnt)
				buildmultimenu(MenuButtonOptions,key,"Drop", invnt)
				MenuButtonOptions:Open()
			end


//COMMON MENU BITS

function buildmultimenu(DMenu,key,fcn,Inventory)
	local drop=DMenu:AddSubMenu(fcn,function() end)
	drop:AddOption("One", function() RunConsoleCommand(fcn,key,1) Inventory:Close() end)
	drop:AddOption("Five", function () RunConsoleCommand(fcn,key,5) Inventory:Close() end)
	drop:AddOption("Ten",function () RunConsoleCommand(fcn,key,10) Inventory:Close() end)
	drop:AddSpacer()
	drop:AddOption("All",function() RunConsoleCommand(fcn,key,"all") Inventory:Close() end)
	drop:AddSpacer()
	drop:AddOption("Other", function()  end)
	return drop
end

function buildcrate(DMenu,key,Inventory)
	print("start")
	local trace=LocalPlayer():GetEyeTraceNoCursor()
	if(!trace.Entity:IsValid()) then return end
	if(trace.Entity:GetClass()!="transportcrate") then return end

	if(trace.StartPos:Distance(trace.HitPos) >300) then return end
	key=key.." "..trace.Entity:EntIndex()
	buildmultimenu(DMenu,key,"PlaceInCrate",Inventory)
end

function singlemenu(DMenu,key,name,Inventory)
	return DMenu:AddOption(name, function() RunConsoleCommand(name,key) Inventory:Close() end)
end